﻿@{
    Layout = null;
}
@using KingRoad.EPM.Common.Helper
<script type="text/javascript">

    var Items_jqgrid_lastID = 0; //最后一次选中的行ID
    var Items_edit_url = "/Permission/Items/Edit/"; //编辑路径
    var Permission_Items_mainContent_Height = 0;
    $(function () {
        //计算分栏高度
        Permission_Items_mainContent_Height = $("#tabContent").innerHeight() - $(".panelBar",navTab.getCurrentPanel()).outerHeight();
        $("#Permission_Items_mainContent").height(Permission_Items_mainContent_Height);
    });
    $(document).ready(function () {

        GridGet();
    });

    function GridGet() {
        $("#ItemsTable").jqGrid({
            url: "/Permission/Items/GetItemsByPage",
            datatype: "json",
            mtype: "post",
            colNames: ['ID', '编号', '名称', '目标表', '编号字段', '名称字段', '值字段', '有效', '描述', '表'],
            colModel: [
                        { name: 'Id', index: 'Id', width: 20, align: "center", sortable: false, hidden: true },
                        { name: 'Code', index: 'Code', width: 380, align: "center", sortable: false },
                        { name: 'FullName', index: 'FullName', width: 300, align: "center", sortable: false },
                        { name: 'TargetTable', index: 'TargetTable', width: 450, align: "center", sortable: false },
                        { name: 'UseItemCode', index: 'UseItemCode', width: 350, align: "center", sortable: false },
                        { name: 'UseItemName', index: 'UseItemName', width: 350, align: "center", sortable: false },
                        { name: 'UseItemValue', index: 'UseItemValue', width: 350, align: "center", sortable: false },
                        { name: 'Enabled', index: 'Enabled', width: 350, align: "center", formatter: "checkbox", sortable: false },
                        { name: 'Description', index: 'Description', width: 350, align: "center", sortable: false },
                        { name: 'TargetTable', index: 'TargetTable', width: 350, align: "center", sortable: false, hidden: false }
                       ],
            loadError: function (xhr, status) {
                alertMsg.error(xhr.responseText);
            },
            loadComplete: function (xhr) {
                var ajaxbg = $("#background,#progressBar,#lui_ItemsTable");
                ajaxbg.hide();
            },
            onSelectRow: Items_GetIDbyEdit,
            autowidth: true,
            shrinkToFit: true,
            multiselect: false,
            multiselectWidth: 50,
            sortable: false,
            viewrecords: true,
            sortorder: "desc",
            rowNum: -1,
            jsonReader: {
                repeatitems: false
            },
            height: Permission_Items_mainContent_Height - 23
        }).navGrid('#pager', { edit: false, add: false, del: false, refresh: false, search: false });
    }

    //获取所有选中行的ID    1返回行ID   2返回角色ID
    function GetSelectID() {
        var Items_Jqgrid = $("#ItemsTable");
        var Items_Index_Get_ListID = $("#ItemsTable").jqGrid("getGridParam", "selrow");
        if (Items_Index_Get_ListID == "")
            return "";
        var Items_Index_ListID = "";
        var temp = "";
        temp = Items_Jqgrid.getCell(Items_Index_Get_ListID, "Id").toString();
        if (temp != "" && temp != "false") {
            Items_Index_ListID = temp;
        }
        return Items_Index_ListID;
    }

    //对选项字典执行删除操作
    $("#del_permission_items_index").click(function () {
        var Items_Grid_SelectID = GetSelectID();
        if (Items_Grid_SelectID == "") {
            alertMsg.error("至少要勾选一条记录！");
            return false;
        }
        else {
            alertMsg.confirm("您确定要删除吗？", {
                okCall: function () {
                    $.post("/Permission/Items/Delete", { "ItemsArryID": Items_Grid_SelectID }, dialogDeleted, "json");
                }
            });
        }
    });
    function dialogDeleted(json) {
        //提交回调
        //1 接收参数 2 判断成功与否 3 根据返回的数据在树上新增节点
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //更新成功
            var Jqgrid_ListID = $("#ItemsTable").jqGrid("getGridParam", "selrow").toString();
            $("#ItemsTable").delRowData(Jqgrid_ListID);
            alertMsg.correct("成功删除1条记录！");
        }
        else {
            alertMsg.error(json.message);
        }
    }

    function dialogCreating(json) {
        //提交回调
        //1 接收参数 2 判断成功与否 3 根据返回的数据在树上新增节点       
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //更新成功
            alertMsg.correct(json.message);
            $("#ItemsTable").trigger("reloadGrid");
            //            var newRole_row = $("#Role_Create").serialize();
            //            $("#RoleTable").addJSONData(eval(newRole_row));
        }
        else {
            alertMsg.error(json.message);
        }
        $.pdialog.closeCurrent();
        $("#background,#progressBar,#lui_ItemsTable").hide();
    }

    function dialogEditing(json) {
        //提交回调
        //1 接收参数 2 判断成功与否 3 根据返回的数据在树上新增节点       
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //更新成功
            alertMsg.correct(json.message);
            $("#ItemsTable").trigger("reloadGrid");
            //            var newRole_row = $("#Role_Create").serialize();
            //            $("#RoleTable").addJSONData(eval(newRole_row));
        }
        else {
            alertMsg.error(json.message);
        }
        $.pdialog.closeCurrent();
        $("#background,#progressBar,#lui_ItemsTable").hide();
    }

    //为修改而获取ID,JQgrid行的点击事件
    function Items_GetIDbyEdit(rowid, status) {
        if ($("#ItemsTable").jqGrid("getGridParam", "selrow").toString() == "") {
            $("#Items_edit").attr("href", "/Permission/Items/Edit/{sid_Items}");
            $("#Items_Details").attr("href", "/Permission/Items/Details/{sid_Items}");
            return;
        }
        var tempID = 0;
        var targetable = "";

        tempID = $("#ItemsTable").getCell(rowid, "Id");
        targetable = $("#ItemsTable").getCell(rowid, "TargetTable");
        if (targetable == "Items_")
            targetable = "";
        if (tempID == 0)
            return;
        $("#Items_edit").attr("href", Items_edit_url + tempID.toString());

        if (targetable == "")
            $("#Items_Details").hide();
        else {
            $("#Items_Details").show().attr("href", "/Permission/Items/Details/" + tempID.toString());
        }
        role_jqgrid_lastID = tempID;
    }

    //实现模糊查询
    $().ready(function () {
        $("#txtkeyword_Permission_Items_Index").keyup(
        function () {
            $("#ItemsTable tr:gt(0)").hide();
            var $d = $("#ItemsTable tr:gt(0)").filter(":contains('" + $.trim($("#txtkeyword_Permission_Items_Index").val()) + "')");
            $d.show();
        }
      )
    })
</script>
<div class="page">
    @*顶部按钮*@
    <div class="panelBar">
        <ul class="toolBar">
            <li class="nobg">关键字：<input type="text" id="txtkeyword_Permission_Items_Index" />
            </li>

            <li class="line">line</li><li>@Html.PermissionButton("Permission.Items.Create", "", "add", "/Permission/Items/Create", "Items_Create", "dialog", "", "true", "480", "360", "添加")</li>
            <li>@Html.PermissionButton("Permission.Items.Delete", "del_permission_items_index", "delete", "javascript:void(0);", "", "", "", "", "删除")</li>
            @*一般情况下不允许修改已经创建的表*@ @*<li>@Html.PermissionButton("Permission.Items.Edit", "Items_edit", "edit", "/Permission/Items/Edit/{sid_Items}", "Items_edit", "dialog", "", "true", "修改")</li>*@
            <li>@Html.PermissionButton("Permission.Items.Details", "Items_Details", "edit", "/Permission/Items/Details/{sid_Items}", "Items_Details", "dialog", "选项细目", "true", "640", "480", "选项细目")</li>
        </ul>
    </div>
    <div id="Permission_Items_mainContent">
            <table id="ItemsTable">
            </table>
            <div id="pager">
            </div>
    </div>
</div>
